import Vue from 'vue';
import VueRouter from 'vue-router';
import { routes } from './router'

Vue.use(VueRouter);

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

router.beforeEach((to, from, next) => {
  //return next(); //不验证

  const token = sessionStorage.getItem('token');
  const noTokenPath = ["/desktop", "/list","space-time"];
  const isNoTokenPath = noTokenPath.some(path => to.path.indexOf(path) > -1);
    
  if (isNoTokenPath) {
    return next();
  }
  if (!token) {
    if (to.name === 'Login') {
      next();
      return;
    }
    next({ name: 'Login' })
  } else {
    next();
  }
})

export default router;
